package TraLaLa.Ventanas.User;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import TraLaLa.Cliente.ClienteUser.UserControler;
import TraLaLa.Servidor.GestorCanciones.CancionDTO;
import TraLaLa.Servidor.GestorUsuarios.Usuario;
import TraLaLa.Ventanas.Song.ListWindow;

public class UserPanel extends JPanel implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel img;
	private JLabel nick;
	private JLabel name;
	private JLabel puntos;
	private JButton lPermanentes;
	private JButton lFavoritos;
	private Usuario usuario;
	private UserControler controler;
	public UserPanel(Usuario user, UserControler controler){
		this.controler= controler;
		usuario=user;
		img = new JLabel(new ImageIcon(getClass().getResource("/img/user.png")));
		
		this.nick = new JLabel(usuario.getNick());
		this.name = new JLabel(usuario.getNombre());
		this.puntos = new JLabel(new Integer(usuario.getPuntos()).toString());
		lPermanentes = new JButton("Lista Permanentes");
		lFavoritos = new JButton("Lista Favoritos");
		this.setLayout(null);
		
		this.add(img);
		this.add(this.nick);
		this.add(this.name);
		this.add(this.puntos);
		this.add(lFavoritos);
		this.add(lPermanentes);
		
		lFavoritos.setBounds(5,150,290,50);
		lPermanentes.setBounds(5,200,290,50);
		this.nick.setBounds(150, 50, 100, 30);
		this.name.setBounds(150, 80, 100, 30);
		this.puntos.setBounds(150, 100, 100, 30);
		img.setBounds(15, 15, 100, 100);
		img.setBorder(BorderFactory.createLineBorder(Color.black));
		lPermanentes.addActionListener(this);
		this.setSize(300,300);
		this.setVisible(true);
		this.setBorder(BorderFactory.createLineBorder(Color.black));
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		try {
			ArrayList<CancionDTO> lista=controler.listaPermanentes(usuario);
			ListWindow listWind= new ListWindow(lista);
			listWind.setVisible(true);
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
	}
	public void actualizar(){
		nick.setText(usuario.getNick());
		name.setText(usuario.getNombre());
		puntos.setText(new Integer(usuario.getPuntos()).toString());
		this.repaint();
	}

}
